<template>
  <div class="app-container">
    <query></query>

    <el-table
      :data="employeeData"
      border
      fit
      highlight-current-row
      style="width: 100%"
      @sort-change="sortChange"
    >
      <el-table-column
        :label="employeeRemark.id"
        prop="id"
        sortable="custom"
        align="center"
        width="80"
        :class-name="getSortClass('id')"
      >
        <template #default="{ row }">
          <span>{{ row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column
        :label="employeeRemark.username"
        width="180px"
        align="center"
      >
        <template #default="{ row }">
          <span>{{ row.username }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="employeeRemark.phoneNumber" min-width="150px">
        <template #default="{ row }">
          <span class="link-type" @click="handleUpdate()">{{
            row.phoneNumber
          }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="sex" :label="employeeRemark.sex" width="120">
      </el-table-column>
      <el-table-column prop="age" :label="employeeRemark.age" width="120">
      </el-table-column>
      <el-table-column
        prop="role.name"
        :label="employeeRemark.position"
        width="120"
      >
      </el-table-column>
      <el-table-column
        align="center"
        :label="employeeRemark.createdTime"
        width="200"
      >
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.createdTime }}</span>
        </template>
      </el-table-column>
      <el-table-column
        :label="employeeRemark.operation"
        align="center"
        width="300px"
        class-name="fixed-width"
      >
        <template #default="{ row }">
          <el-button type="primary" size="mini" @click="handleSeekInfo()">
            {{ employeeRemark.seek }}
          </el-button>
          <el-button type="primary" size="mini" @click="handleEdit()">
            {{ employeeRemark.edit }}
          </el-button>
          <el-button size="mini" type="danger" @click="handleDelete()">
            {{ employeeRemark.danger }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :total="employeeRemark.total"
      v-show="employeeRemark.total > 0"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="employeeRemark.currentPage"
      :page-sizes="[10, 20, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper"
    />

    <!--          see information dialogue     *************************************** -->
    <el-dialog
      :title="dialogueRemark.title"
      :visible="dialogueRemark.isVisible"
    >
      <el-form
        :model="dialogueValue"
        label-position="left"
        label-width="100px"
        style="width: 400px; margin-left: 50px"
      >
        <el-form-item :label="dialogueRemark.name" prop="title">
          <el-input v-model="dialogueValue.name" />
        </el-form-item>
        <el-form-item :label="dialogueRemark.sex" prop="title">
          <el-input v-model="dialogueValue.sex" />
        </el-form-item>
        <el-form-item :label="dialogueRemark.phoneNumber" prop="title">
          <el-input v-model="dialogueValue.phoneNumber" />
        </el-form-item>

        <el-form-item :label="dialogueRemark.age" prop="title">
          <el-input v-model="dialogueValue.age" />
        </el-form-item>
        <el-form-item :label="dialogueRemark.position" prop="title">
          <el-input v-model="dialogueValue.position" />
        </el-form-item>
        <el-form-item :label="dialogueRemark.createdTime" prop="timestamp">
          <el-date-picker
            v-model="dialogueValue.createdTime"
            type="datetime"
            placeholder="Please pick a date"
          />
        </el-form-item>
      </el-form>
      <div class="dialog-footer">
        <el-button @click="dialogueRemark.isVisible = false">
          {{ dialogueRemark.cancel }}
        </el-button>
        <el-button type="primary" @click="dialogueRemark.isVisible = false">
          {{ dialogueRemark.confirm }}
        </el-button>
      </div>
    </el-dialog>
    <edit-dialogue-vue
      :isVisible="employeeRemark.isEditVisible"
      @updateData="updateData"
      @hide="hide"
    ></edit-dialogue-vue>
  </div>
</template>

<script>
import editDialogueVue from './editDialogue.vue';
import query from "./query/index.vue";

export default {
  components: {
    query,
    editDialogueVue
  },
  data() {
    return {
      employeeRemark: {
        id: "序号",
        username: "姓名",
        phoneNumber: "电话号码",
        sex: "性别",
        age: "年龄",
        position: "职位",
        operation: "操作",
        seek: "查看信息",
        edit: "调整职位",
        danger: "删除",
        createdTime: "入职时间",
        total: "10",
        currentPage: "1",
        isEditVisible: false,
      },
      employeeData: [],
      dialogueRemark: {
        title: "个人信息",
        name: "名字",
        sex: "性别",
        phoneNumber: "电话号码",
        age: "年龄",
        position: "职位",
        createdTime: "入职时间",
        cancel: "取消",
        confirm: "确认",
        isVisible: false,
      },
      dialogueValue: {
        name: "steven",
        sex: "男",
        phoneNumber: "123456789",
        age: "22",
        position: "经理",
        createdTime: "2023/3/16 09:51",
      },
      // dialogueAddRemark: {
      //   title: "添加员工",
      //   name: "名字",
      //   sex: '性别',
      //   phoneNumber: '电话号码',
      //   position: '职位',
      //   cancel: '取消',
      //   confirm: '确认',
      //   isVisible: 'false'
      // },
      // dialogueAddValue: {
      //   name: '',
      //   sex: '',
      //   phoneNumber: '',
      //   position: '',
      // }
    };
  },
  created() {
    this.getEmployeeData();
  },
  methods: {
    getEmployeeData() {
      this.$store
        .dispatch("request/get", "/user/list/employee")
        .then((data) => {
          this.employeeData = data;
        });
    },
    getSortClass(key) {
      console.log(key + "***");
    },
    sortChange(data) {
      const { prop, order } = data;
      if (prop === "id") {
        dataMap.sortByID(order);
      }
    },
    handleSeekInfo() {
      this.dialogueRemark.isVisible = true;
    },
    handleEdit(){
      this.employeeRemark.isEditVisible = true
    },
    handleDelete() {
      this.$message.success("删除成功!!")
    },
    handleCurrentChange(page) {
      console.log(page);
    },
    handleSizeChange(val) {
      console.log(val);
    },
    updateData(){

    },
    hide(){
      this.employeeRemark.isEditVisible = false
    }

  },
};
</script>